package com.psm.controller;

import com.jfinal.plugin.activerecord.Record;
import com.jfinal.aop.Before;
import com.psm.interceptor.IndexInterceptor;
import com.psm.model.SysUser;
import com.psm.validator.LoginValid;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by cheam on 15/6/19.
 */
@Before(IndexInterceptor.class)
public class IndexController extends BaseController {

    public void index(){
        List<Record> menu = SysUser.me.qryUserMenu(getCurrentUserId());
        setSessionAttr("user_menu",SysUser.me.qryPermission(getCurrentUserId()));
        setSessionAttr("permission_button",SysUser.me.get_menu_permission(getCurrentUserId()));

        setAttr("menu",menu);
        setAttr("user_name",getCurrentUser().getStr("name"));
        render("index.html");
    }

    public void get_user_permission(){
        List<Record> menu = getSessionAttr("user_menu");
        if(null == menu){
            menu = SysUser.me.qryUserMenu(getCurrentUserId());
        }
        this.rendJson_(1, "操作成功",menu);
    }

}
